package com.sl.eurekaserver.service;

import java.util.concurrent.Future;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.command.AsyncResult;

@Service
public class HelloService {

	@Autowired
	RestTemplate restTemplate;

	@HystrixCommand(fallbackMethod = "helloFailback")
	public String helloService() {
		return restTemplate.getForEntity("http://HELLO-SERVICE/hello",
				String.class).getBody();
	}

	@HystrixCommand
	public Future<String> helloServiceAsync(){
		return new AsyncResult<String>() {

			@Override
			public String invoke() {
				return restTemplate.getForEntity("http://HELLO-SERVICE/hello",
						String.class).getBody();			
			}
			   
		};
	}
	public String helloFailback(Throwable throwable) {
		return "error";
	}
}
